<?php
/***
	客户联系记录表，包括：
	1. 根据客户ID查询联系记录 get_by_client($client_id)
	
**/
class Bid_project_code_model extends CI_Model {
	
	public function __construct() {
		$this->load->database();
	}
	
	public function get_by_year ($year) {
		$sqlstring = "select * from projects where code LIKE '%MP".$year."%'";
		$query = $this->db->query($sqlstring);
		return $query->result_array();
	}
	
	public function get_by_id ($id) {
		$sqlstring = "select * from projects where projects.id = ".$id;
		$query = $this->db->query($sqlstring);
		return $query->row_array();
	}
	//新建
	public function create () {
		$data = array(
			'code' => $this->input->post('project_code'),
			'name' => $this->input->post('project_name'),
			'client' => $this->input->post('client'),
			'equipment' => $this->input->post('equipment'),
			'status' => $this->input->post('status'),
			'remark' => $this->input->post('remark')
		);
		
		$this->db->insert('projects', $data);
	}
	
	//按id删除
	public function delete_by_id ($id) {
		
		$this->db->delete('projects', array('id' => $id));
		
	}
	
	//根据id更新
	public function update_by_id ($id) {
		$data = array (
			'code' => $this->input->post('project_code'),
			'name' => $this->input->post('project_name'),
			'client' => $this->input->post('client'),
			'equipment' => $this->input->post('equipment'),
			'status' => $this->input->post('status'),
			'remark' => $this->input->post('remark')
		);
		
		$this->db->where('id', $id);
		$this->db->update('projects', $data);
	}
}
